<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta charset="UTF-8">
    <title>招聘岗位发布</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../css/main.css" media="all">
    <link rel="stylesheet" href="../../css/enterprisePostJob.css" media="all">
    <link rel="stylesheet" href="../../css/jquery.tagsinput.css">
</head>


<body>
<!--主体内容-->
<div class="layui-fluid">
    <form class="layui-form" action="" lay-filter="component-form-group">
        <div class="layui-row">
            <div class="layui-col-xs12 layui-col-sm12 layui-col-md12">
                <div class="layui-form-item"></div>
                <div class="layui-form-item" style="text-align: center">
                    <div class="layui-inline" style="width: 60%">
                        <label class="layui-form-label">岗位名称</label>
                        <input placeholder="岗位名称" type="text" name="jobname" lay-verify="required" class="layui-input">
                    </div>
                </div>
            </div>
        </div>

        <div class="layui-row">
            <div class="layui-col-xs12 layui-col-sm12 layui-col-md12">
                <div class="layui-form-item" style="text-align: center">
                    <div class="layui-inline" style="width: 29.6%">
                        <label class="layui-form-label">学历要求</label>
                        <select name="educationrequirements" lay-verify="required">
                            <option value=""></option>
                            <option value="初中及以下">初中及以下</option>
                            <option value="中专/中技">中专/中技</option>
                            <option value="高中">高中</option>
                            <option value="大专">大专</option>
                            <option value="本科">本科</option>
                            <option value="硕士">硕士</option>
                            <option value="博士">博士</option>
                            <option value="不限">不限</option>
                        </select>
                    </div>
                    <div class="layui-inline" style="width: 29.6%">
                        <label class="layui-form-label">需求人数</label>
                        <input placeholder="需求人数" type="text" name="needpeople" lay-verify="negative|count|required"
                               class="layui-input" style="width: 29%">
                    </div>
                </div>
            </div>
        </div>

        <div class="layui-row">
            <div class="layui-col-xs12 layui-col-sm12 layui-col-md12">
                <div class="layui-form-item" style="text-align: center">
                    <div class="layui-inline" style="width: 29.6%">
                        <label class="layui-form-label">工作经验</label>
                        <select name="workingexperience" lay-verify="required">
                            <option value=""></option>
                            <option value="在校生">在校生</option>
                            <option value="应届生">应届生</option>
                            <option value="1年以内">1年以内</option>
                            <option value="1-3年">1-3年</option>
                            <option value="3-5年">3-5年</option>
                            <option value="5-10年">5-10年</option>
                            <option value="10年以上">10年以上</option>
                            <option value="不限">不限</option>
                        </select>
                    </div>
                    <div class="layui-inline" style="width: 29.6%">
                        <label class="layui-form-label">工作地点</label>
                        <input placeholder="工作地点" type="text" name="workplace" lay-verify="required"
                               class="layui-input">
                    </div>
                </div>
            </div>
        </div>

        <div class="layui-row">
            <div class="layui-col-xs12 layui-col-sm12 layui-col-md12">
                <div class="layui-form-item" style="text-align: center">
                    <div class="layui-inline" style="width: 29.6%">
                        <label class="layui-form-label">薪资</label>
                        <select name="jobsalary" lay-filter="aihao">
                            <option value=""></option>
                            <option value="2千以下">2千以下</option>
                            <option value="2-3千">2-3千</option>
                            <option value="3-4千">3-4千</option>
                            <option value="4-5千">4-5千</option>
                            <option value="5-6千">5-6千</option>
                            <option value="6-8千">6-8千</option>
                            <option value="0.8-1万">0.8-1万</option>
                            <option value="1-2万">1-2万</option>
                            <option value="2-3万">2-3万</option>
                            <option value="3-4万">3-4万</option>
                            <option value="4-5万">4-5万</option>
                            <option value="5万以上">5万以上</option>
                        </select>
                    </div>
                    <div class="layui-inline" style="width: 29.6%">
                        <label class="layui-form-label">工作类型</label>
                        <select name="type" id="jobtype">
                            <option value="">请选择工作类型</option>
                        </select>
                    </div>
                </div>
            </div>
        </div>

        <div class="layui-row">
            <div class="layui-col-xs12 layui-col-sm12 layui-col-md12">
                <div class="layui-form-item" style="text-align: center;height: 130px">
                    <div class="layui-inline" style="width: 60%;height: 80%">
                        <label class="layui-form-label">公司福利</label>
                        <input id="tags_1" type="text" class="tags layui-input" value="五险一金,餐补,带薪年假"/>
                    </div>
                </div>
            </div>
        </div>
        <script type="text/javascript" src="../../js/jquery-3.5.1.js"></script>
        <script src="../../js/jquery.tagsinput.js"></script>
        <script>
            $(function () {
                $('#tags_1').tagsInput({
                    width: 'auto'
                });
            })
        </script>

        <div class="layui-row">
            <div class="layui-col-xs12 layui-col-sm12 layui-col-md12">
                <div class="layui-form-item" style="text-align: center;height: 190px">
                    <div class="layui-inline" style="width: 60%;height: 80%">
                        <label class="layui-form-label">职位描述</label>
                        <textarea placeholder="请输入职位描述" class="layui-textarea" name="descriptionofjob"
                                  style="resize: none;font-size: 18px"></textarea>
                    </div>
                </div>
            </div>
        </div>

        <div class="layui-row">
            <div class="layui-col-xs12 layui-col-sm12 layui-col-md12">
                <div class="layui-form-item" style="text-align: center;height: 190px">
                    <div class="layui-inline" style="width: 60%;height: 80%">
                        <label class="layui-form-label">岗位要求</label>
                        <textarea placeholder="请输入岗位要求" class="layui-textarea "
                                  style="resize: none;font-size: 18px" name="jobrequirement"></textarea>
                    </div>
                </div>
            </div>
        </div>

        <div class="layui-row">
            <div class="layui-col-xs12 layui-col-sm12 layui-col-md12">
                <div class="layui-form-item"></div>
                <div class="layui-form-item"></div>
                <div class="layui-form-item" style="text-align: center">
                    <button class="layui-btn" style="background-color: #ff6000" lay-submit lay-filter="postJob">发布岗位
                    </button>
                </div>
            </div>
        </div>

        <div class="layui-row">
            <div class="layui-col-xs12 layui-col-sm12 layui-col-md12">
                <div class="layui-form-item" style="height: 50px"></div>
            </div>
        </div>
    </form>
</div>

<script src="../../libs/layui/layui.js"></script>
<script src="../../js/model.js"></script>
<script type="text/javascript">
    layui.use(['form', 'element', 'layer', 'jquery', 'okLayer'], function () {
        let element = layui.element;
        let layer = layui.layer;
        let form = layui.form;
        let $ = layui.jquery;
        let okLayer = layui.okLayer;

        //自建规则验证
        form.verify({
            negative: [
                /^[1-9]\d*$/
                , '人数只能为正整数！'
            ],
            count: [
                /^(\+?[1-9]\d{0,2}|\+?1000)$/
                , '人数不能超过1000！'
            ]
        });

        // 获取contentText
        const ctx = function () {
            let pathName = document.location.pathname;
            let index = pathName.substr(1).indexOf("/");
            let result = pathName.substr(0, index + 1);
            return result;
        }();

        // 获取enterprise
        var enterprise = JSON.parse(window.sessionStorage.getItem("enterprise"));
        endetection(enterprise);
        $('#tags_1').tagsInput({
            width: 'auto'
        });

        function gettagdata() {
            var array = new Array();
            $('#tags_1_tagsinput >span').each(function (index) {
                var objtext = $(this).text();
                array.push(objtext.replace("x", "").trim());
            })
            return array.toString();
        }

        /**
         * 企业权限检测
         * @param en 企业对象 obj
         */
        function endetection(en) {
            if (en.certificationstatus == "0") {
                parent.layer.msg("你还未认证，认证后才可发布岗位", {icon: 0, time: 1000}, function () {
                    location.href = "enterpriseAuth.html";
                })
            } else if (en.certificationstatus == "1") {
                parent.layer.msg("审核通过才能发布岗位哦", {icon: 0, time: 1000}, function () {
                    parent.location.reload();
                })
            } else if (en.certificationstatus == "3") {
                parent.layer.msg("审核通过才能发布岗位哦", {icon: 0, time: 1000}, function () {
                    parent.location.reload();
                })
            } else {
                laodjontype();
            }
        }

        /**
         * 加载岗位类型
         */
        function laodjontype() {
            //加载层遮罩
            var loadindex;
            //加载岗位类型
            $.ajax({
                url: ctx + "/ygssecs/getjobType",
                type: 'GET',
                dataType: 'JSON',
                beforeSend: function () {
                    loadindex = layer.load(1, {shade: 0.3});
                }
            }).done(function (datas) {
                var list = datas['data'];
                var option;
                for (var i = 0; i < list.length; i++) {
                    option += "<option value='" + list[i]['typeid'] + "'>" + list[i]['typename'] + "</option>";//拼接option中的内容
                }
                $("#jobtype").append(option);//将option的拼接内容加入select中，注意选择器是select的ID
                form.render('select');//重点：重新渲染select
                layer.close(loadindex);//关闭加载遮罩
            }).fail(function () {
                console.log("error");
            });
        }

        //表单提交
        form.on('submit(postJob)', function (data) {
            var tags = gettagdata();
            var enterpriseJob = new EnterpriseJob(null, data.field.jobname, data.field.needpeople, data.field.jobsalary, data.field.educationrequirements, tags, data.field.workingexperience, data.field.descriptionofjob, data.field.jobrequirement, data.field.workplace, null, new JobType(data.field.type), null, enterprise)
            var jsonstr = JSON.stringify(enterpriseJob);
            console.log(data.field) //当前容器的全部表单字段，名值对形式：{name: value}
            $.ajax({
                url: ctx + "/ygssecs/postJob",
                type: 'POST',
                // headers: {"token": sessionStorage.getItem("token")},
                data: {jobjson: jsonstr}
            }).done(function (response) {
                console.log(response);
                if (response.code == 200) {
                    parent.layer.msg(response.msg, {icon: 1, time: 1000}, function () {
                        parent.location.reload();
                    })
                } else {
                    parent.layer.msg(response.msg, {icon: 3, time: 1000}, function () {
                        parent.location.reload();
                    })
                }
            }).fail(function (error) {
                console.log(error);
            });
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });
    });
</script>

</body>
</html>